<template>
  <div class="tab-control">
    <div
      class="tab-control-item"
      :class="{ active: index === currentIndex }"
      v-for="(item, index) in title_list"
      :key="index"
      @click="controlItemClick(index)"
    >
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title_list: {
      type: Array,
      default() {
        return []
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
      typeList:[]
    }
  },
  methods: {
    controlItemClick(index) {
      this.currentIndex = index
      // 触发给 home 组件 tab栏切换事件，发送index标签值
      this.$emit('changeGoodsType',index) 
    },
  },
}
</script>

<style lang="less" scoped>
.tab-control {
  display: flex;
  padding-bottom: 10px;
  .tab-control-item {
    flex: 1;
    text-align: center;
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    &.active {
      span {
        color: @base-color;
        padding: 5px;
        border-bottom: 2px solid @base-color;
      }
    }
  }
}
</style>
